import { request } from '../../request/index'
import { async } from '../../lib/runtime/runtime'
//防抖  定时器
//一般输入框中 防止重复输入 重复发送请求
//定义全局定时器id
Page({
  data: {
    goods: [],
    isFocus: false,//判断取消按钮是否显示
    inputValue: ''
  },
  //Timeid: -1,
  inputquery(e) {//获取输入框文本值
    const { value } = e.detail
    let isFocus = true
    if (!value.trim()) {
      return;
      isFocus = flase
      this.setData({ isFocus: isFocus })
    } else {
      isFocus = true
      this.setData({ isFocus: isFocus, inputValue: value })
      this.qsearch(value)
    }
    /*clearTimeout(this.Timeid)
    this.Timeid = setTimeout(() => {
    
    }, 1000)*/

  },
  async qsearch(query) {
    const res = await request({ url: 'goods/qsearch', data: { query } })
    console.log(res)
    this.setData({
      goods: res.data.message
    })
  },
  cancel() {//点击取消按钮的事件
    let { inputValue } = this.data
    inputValue = ''
    this.qsearch(inputValue)
    this.setData({
      inputValue
    })
  }

})